package it.polimi.traveldream.ejb.entities;

import it.polimi.traveldream.ejbclient.dtos.HotelDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the hotel database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name=Hotel.FIND_HOTELS_AVAILABLE,
			query="SELECT h FROM Hotel h WHERE h.startTrip >= :start AND h.endTrip <= :end AND h.maxAvailability - h.reservations >= :reservations"),
	@NamedQuery(name=Hotel.FIND_HOTELS,
			query="SELECT h FROM Hotel h WHERE h.overpast = :overpast")
})
public class Hotel implements Serializable {
	private static final long serialVersionUID = -6918983603666530231L;
	public static final String FIND_HOTELS_AVAILABLE = "Hotel.findHotelsAvailable";
	public static final String FIND_HOTELS = "Hotel.findHotels";
	private int id;
	private String address;
	private String description;
	private Date endTrip;
	private int maxAvailability;
	private String name;
	private boolean overpast;
	private BigDecimal price;
	private int rating;
	private int reservations;
	private Date startTrip;
	private List<Travelpackage> travelpackages;

	public Hotel() {
		super();
	}

	public Hotel(HotelDTO hotel) {
		super();
		this.id = hotel.getId();
		this.address = hotel.getAddress();
		this.description = hotel.getDescription();
		this.endTrip = hotel.getEndTrip();
		this.maxAvailability = hotel.getMaxAvailability();
		this.name = hotel.getName();
		this.overpast = hotel.isOverpast();
		this.price = hotel.getPrice();
		this.rating = hotel.getRating();
		this.reservations = hotel.getReservations();
		this.startTrip = hotel.getStartTrip();
	}
	

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}


	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	@Temporal(TemporalType.TIMESTAMP)
	public Date getEndTrip() {
		return this.endTrip;
	}

	public void setEndTrip(Date endTrip) {
		this.endTrip = endTrip;
	}


	public int getMaxAvailability() {
		return this.maxAvailability;
	}

	public void setMaxAvailability(int maxAvailability) {
		this.maxAvailability = maxAvailability;
	}


	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public boolean getOverpast() {
		return this.overpast;
	}

	public void setOverpast(boolean overpast) {
		this.overpast = overpast;
	}


	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}


	public int getRating() {
		return this.rating;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}


	public int getReservations() {
		return this.reservations;
	}

	public void setReservations(int reservations) {
		this.reservations = reservations;
	}


	@Temporal(TemporalType.TIMESTAMP)
	public Date getStartTrip() {
		return this.startTrip;
	}

	public void setStartTrip(Date startTrip) {
		this.startTrip = startTrip;
	}


	//bi-directional many-to-many association to Travelpackage
	@ManyToMany(mappedBy="hotels")
	public List<Travelpackage> getTravelpackages() {
		return this.travelpackages;
	}

	public void setTravelpackages(List<Travelpackage> travelpackages) {
		this.travelpackages = travelpackages;
	}

}